package cn.imvc.app.controllers.system;

import java.util.HashSet;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;

import cn.imvc.app.entities.Position;
import cn.imvc.app.models.PositionDepartmentModel;
import cn.imvc.app.models.PositionModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;

public class DepartmentPositionControllerImpl implements
		DepartmentPositionController {
	
	public String departments;
	public String positions;
	public int id;
	public int[] positionid;
	
	public void setId(int id) {
		this.id = id;
	}
	@Autowired
	private PositionDepartmentModel positionDepartmentModel;
	@Autowired
	private PositionModel positionModel;
	
	public String index() {
		departments=positionDepartmentModel.getDepartments();
		return "department-position/index";
	}

	public String show() {
		positions=positionDepartmentModel.getPositionTree(id);
		return "department-position/show";
	}

	public String create() {
		Set<Position> positions=new HashSet<Position>();
		if(positionid!=null)
			for (int pid : positionid) {
				positions.add(positionModel.get(pid));
			}
		positionDepartmentModel.saveDepartmentPosition(id, positions);
		return Render.json(new DialogBean("200", "保存成功","department-rosition","closeCurrent"));
	}

}
